package com.zy.springcloudconsumer.controller;

import com.zy.springcloudconsumer.feign.UserFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @program: spring-cloud
 * @className: UserController.java
 * @description:
 * @author: ZY
 * @create: 2020年11月14日 18:54
 **/

@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private RestTemplate restTemplate;

    @Autowired
    private UserFeignService userFeignService;

    /**
     * 通过ribbon调用微服务
     * @return
     */
    @GetMapping("/getUser1")
    public Map<?, ?> getUser1() {
        System.out.println("1请求消费者成功，消费者开始调用生产者服务");
        return restTemplate.getForObject( "http://spring-cloud-provider/user/getUser", Map.class);
    }

    /**
     * 通过Feign调用微服务
     * @return
     */
    @GetMapping("/getUser2")
    public Map<?, ?> getUser2() {
        System.out.println("2请求消费者成功，消费者开始调用生产者服务");
        return userFeignService.getUser();
    }


}
